package com.springcloud.tools.aspectJ;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author fuc
 * @create 2020-06-18
 */
@Component
@Aspect
@Slf4j
public class controllerAspect {

  /** 声明切入点表达式 */
  @Pointcut(value = "execution(* com.springcloud.tools.controller.SysRoleController.sysRole(..))")
  public void sysRolePointCut() {}

  @Around(value = "sysRolePointCut()")
  @SneakyThrows
  public Object addDeviceTrusteeshipAroundMethod(ProceedingJoinPoint pjp) {
    Object result;
    Object[] paramValues = pjp.getArgs();
    String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
    Map<String, Object> map = (Map<String, Object>) paramValues[1];
    map.forEach(
        (key, value) -> log.info("AOP----key:[{}],value:[{}]", key, value));
    result = pjp.proceed();
    log.info("AOP----:[{}]", result.toString());
    return result;
  }
}
